<script setup lang="ts">
import { onMounted, onBeforeUnmount } from 'vue'
import { RouterView } from 'vue-router'
import zhCN from 'ant-design-vue/es/locale/zh_CN'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import { setRootFontSize } from '@/utils/common'
import { platformStore } from './store'

dayjs.locale('zh-cn')
onMounted(() => {
  const screenWidth = window.innerWidth
  const rootFontSize = (16 * screenWidth) / 1920
  document.documentElement.style.fontSize = rootFontSize.toString() + 'px'
})
// import MyComponet from '@/views/role/index.vue' // role organization
// 下拉菜单跟着父节点或者body
function getPopupContainer(triggerNode: HTMLElement) {
  if (triggerNode && triggerNode.className.indexOf('ant-select') > -1) {
    if (triggerNode.className.indexOf('select-body') > -1) return document.body
    return triggerNode.parentNode
  }
  return document.body
}

// setRootFontSize()
const platStore = platformStore()
document.getElementsByTagName('title')[0].innerHTML = platStore.name
// 监听窗口大小变化事件，重新设置根节点字体大小
window.addEventListener('resize', setRootFontSize)

// CI/CD rebuild后切换路由的问题修复
window.addEventListener('unhandledrejection', (event) => {
  const error = event.reason
  if (
    error instanceof Error &&
    error.message.includes('Failed to fetch dynamically imported module')
  ) {
    // 这里可以执行你的错误处理逻辑
    console.error(
      '发生了 "Failed to fetch dynamically imported module" 错误:',
      error
    )
    window.location.reload()
  }
})

onBeforeUnmount(() => {
  // clearTimeout(verifyTimer)
})
</script>

<template>
  <a-config-provider :locale="zhCN" :getPopupContainer="getPopupContainer">
    <router-view />
    <!-- <MyComponet /> -->
  </a-config-provider>
</template>

<style lang="less">
#app {
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  // background-color: #f0f2f5;
}
</style>
